package cn.tedu.csmall.stock.webapi.timer;

import cn.tedu.csmall.stock.webapi.config.RabbitMQConfig;
import cn.tedu.csmall.stock.webapi.untils.RedisBloomUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;

public class QuartzJob implements Job {
    //利用RabbitTamplate工具类，使用RabbitMQ
//    @Autowired
//    private RabbitTemplate rabbitTemplate;
    @Autowired
    private RedisBloomUtils redisBloomUtils;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //要执行的任务，当前先输出时间做测试
//        System.out.println("----------------------"+System.currentTimeMillis()+"----------------------");
//        LocalDateTime now = LocalDateTime.now();
        //把当前时间发送到RabbitMQ中
        //convertAndSend()方法会帮助我们把要发送的数据类型转成byte[]类型，并且发送
        //convertAndSend([交换机名称],[路由键的名称],[要发送的消息数据]])
//        rabbitTemplate.convertAndSend(RabbitMQConfig.STOCK_EXCHANGE,RabbitMQConfig.STOCK_ROUTE,now);

        //定义一个向布隆过滤器中添加的元素集合
        String[] colors = {"black","pink","red","green","gary","blue"};

        //向布隆过滤器中保存这些元素
        redisBloomUtils.bfmadd("colorBloom",colors);
        //定义一个元素
        String element1 = "pink";
        String element2 = "yellow";
        //输出判断结果
        System.out.println("判断" + element1 + "是否在布隆过滤器中:"
                +redisBloomUtils.bfexists("colorBloom",element1));
        System.out.println("判断" + element2 + "是否在布隆过滤器中:"
                +redisBloomUtils.bfexists("colorBloom",element2));
    }
}
